// Span - Version 1.0
// This script takes the layer assigned to span_layer and scales/rotates/translates
// it so that it stretches between the layers chosen in popups one and two.

//      LAYER                                               PROPERTY                     CHANNEL
//      ------                                              ----------                     --------
// 1: layer to stretch from                        doesn't matter                doesn't matter
// 2: layer to stretch to                            doesn't matter                doesn't matter
//
// span_layer: layer which is stretched between layers 1 and 2

span_layer = "your layer here";				// change to your own layer's name or number

l1 = pop_layer(1);
l2 = pop_layer(2);

// Assign position to midpoint between l1 and l2
value(span_layer, position) = (value(l1, position) + value(l2, position)) / 2;

// compute the vector between l1 and l2
delta = value(l1, position) - value(l2, position);

// compute the rotation of the layer by converting the vector to degrees
value(span_layer, rotation) = -rad_to_deg( atan2(delta[X], delta[Y]) ) + 90;

// assign the scale of the span layer to the distance between the two other layers
value(span_layer, scale)[X] = length(delta) / layer_size(span_layer)[X] * 100;
